unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    function discriminant(x, y : real):real;
    procedure FormPaint(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  x0, y0, x1, y1 : integer;
  d, e : real;

implementation

{$R *.dfm}

function TForm1.discriminant(x, y: real): real;
var
  a, b : integer;
begin
  a := y0 - y1;
  b := x1 - x0;
  result := a*x + b*y + (x0*y1 - x1*y0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  x0 := 0;
  y0 := 0;
  x1 := 600;
  y1 := 100;               //xielv zongshi  0<d<0.5  !
  d := -0.5;
  e := -0.5;
end;


procedure TForm1.FormPaint(Sender: TObject);
var
  x, y, i : integer;
  k : real;
begin
  k := (y1 - y0)/(x1 - x0);
  x := x0;
  y := y0;
  Canvas.Pen.Color := clred;
  Canvas.Pen.Width := 2;
  Canvas.MoveTo(x,y);
  Canvas.LineTo(x,y);
  {for i := 0 to x1 do
  begin
    Canvas.MoveTo(x,y);
    Canvas.LineTo(x,y);
    Inc(x);
    e := e + k;
    if e>=0 then
    begin
      Inc(y);
      e := e-1;
    end;
  end;}

     { or }

  while x < x1 do
  begin
    if d>=0 then
    begin
      d := d - 1;
      Inc(y);
    end;
    Inc(x);
    d := d + k;
    Canvas.MoveTo(x,y);
    Canvas.LineTo(x,y);
  end;

end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Form1.Label1.Caption:='X='+IntToStr(X);
  Form1.Label2.Caption:='Y='+IntToStr(Y);
end;

end.
